home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI O2 Out of Box Experience 2.2
/
SGI O2 Out of Box Experience 2.2.iso
/
SysTour
/
ROI.java
< prev
next >
Wrap
Text File
|
1998-05-26
|
8KB
|
291 lines
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.util.Enumeration;
public class ROI extends Applet{
// Button States
final private byte UNUSED = -1;
final private byte IDLE = 0;
final private byte HILIGHT = 1;
final private byte PRESSED = 2;
private byte buttonState = IDLE;
// Media Tracker ID's for Various Imags (Dictates Load Order)
final private int BACKGROUND_ID = 0;
final private int IMAGE_ID = 1000;
final private int HILIGHT_ID = 2000;
final private int PRESSED_ID = 3000;
final private int HELP_ID = 4000;
Image[] regionHilightImage; // Region Hilight Images
Image[] regionPressedImage; // Region Pressed Images
Image backgroundImg; // Idle Image
Polygon[] region;
Polygon regionHilightLocation;
Polygon regionPressedLocation;
URL[] url;
HelpApplet helpApplet = null;
AudioClip audio;
// Image Locations
Point imgBackgroundLoc = null;
// Miscelaneous
int imageCount, regionCount;
int which;
int time = 0;
int framesPerSecond;
int hilightRegion = UNUSED;
Image offscreenImg = null;
Graphics offscreenGraphics = null;
String targetStr = null;
// End Variables Declarations
// Begin Methods
public void update(Graphics g){
if (offscreenImg == null)
offscreenImg = createImage(size().width,size().height);
if (offscreenGraphics == null)
offscreenGraphics = offscreenImg.getGraphics();
draw(offscreenGraphics);
g.drawImage(offscreenImg,0,0,this);
}
public void paint(Graphics g){
update(g);
}
public void draw(Graphics g){
super.paint(g);
if (backgroundImg != null)
g.drawImage(backgroundImg, imgBackgroundLoc.x, imgBackgroundLoc.y, this);
if (hilightRegion != UNUSED){
Point p;
switch (buttonState){
case HILIGHT:
if (regionHilightImage != null){
p = new Point(regionHilightLocation.xpoints[hilightRegion],
regionHilightLocation.ypoints[hilightRegion]);
g.drawImage(regionHilightImage[hilightRegion],p.x,p.y,this);
}
break;
case PRESSED:
if (regionPressedImage != null){
p = new Point(regionPressedLocation.xpoints[hilightRegion],
regionPressedLocation.ypoints[hilightRegion]);
g.drawImage(regionPressedImage[hilightRegion],p.x,p.y,this);
}
break;
}
}
}
public void init(){
MediaTracker tracker = new MediaTracker(this);
// Load Background Image Parameters
//
// The background image will appear at all times and may
// have a blue screen which allows each of the movie images
// to be placed within the image.
//
// <PARAM NAME="BACKGROUND_IMAGE" VALUE="myimage.gif">
// <PARAM NAME="BACKGROUND_IMAGE_LOCATION" VALUE="(x, y)">
//
String backgroundImgStr = getParameter("BACKGROUND_IMAGE");
String backgroundLocationStr = getParameter("BACKGROUND_IMAGE_LOCATION");
if (backgroundImgStr != null){
backgroundImg = getImage(getDocumentBase(), backgroundImgStr);
tracker.addImage(backgroundImg,BACKGROUND_ID);
}
if (backgroundLocationStr != null)
imgBackgroundLoc =
StringConversion.string2Point(backgroundLocationStr);
else
imgBackgroundLoc = new Point(0,0);
// Load Region Parameters
//
// Regions are rectangular regions of interest whenever the
// cursor enters one of these regions, the corressponding
// region help image will be loaded into the display box.
//
// <PARAM NAME="TARGET" VALUE="_contents">
// <PARAM NAME="REGION_COUNT" VALUE="1">
// <PARAM NAME="REGION_HILIGHT_IMAGE_BASENAME" VALUE="HILIGHT">
// <PARAM NAME="REGION_PRESSED_IMAGE_BASENAME" VALUE="pressed">
// <PARAM NAME="REGION_HILIGHT_IMAGE_LOCATIONS" VALUE="(x, y)">
// <PARAM NAME="REGION_PRESSED_IMAGE_LOCATIONS" VALUE="(x, y)">
//
// <PARAM NAME="REGION_0" VALUE="(20, 20), (30, 30)">
// <PARAM NAME="REGION_0_URL" VALUE="http://www.sgi.com">
//
String regionCountStr = getParameter("REGION_COUNT");
String regionHilightBasename = getParameter("REGION_HILIGHT_IMAGE_BASENAME");
String regionPressedBasename = getParameter("REGION_PRESSED_IMAGE_BASENAME");
String regionHilightLocationStr = getParameter("REGION_HILIGHT_IMAGE_LOCATIONS");
String regionPressedLocationStr = getParameter("REGION_PRESSED_IMAGE_LOCATIONS");
targetStr = getParameter("TARGET");
if (targetStr == null)
targetStr = "_self";
if (regionCountStr != null){
regionCount = Integer.parseInt(regionCountStr);
region = new Polygon[regionCount];
url = new URL[regionCount];
}
if (regionHilightBasename != null)
regionHilightImage = new Image[regionCount];
if (regionPressedBasename != null)
regionPressedImage = new Image[regionCount];
for(int i=0;i<regionCount;i++){
String regionPolygonStr = getParameter("REGION_" + Integer.toString(i));
String regionURLStr = getParameter("REGION_" + Integer.toString(i) + "_URL");
if (regionPolygonStr != null)
region[i] = StringConversion.string2Polygon(regionPolygonStr);
if (regionHilightLocationStr != null)
regionHilightLocation = StringConversion.string2Polygon(regionHilightLocationStr);
if (regionPressedLocationStr != null)
regionPressedLocation = StringConversion.string2Polygon(regionPressedLocationStr);
if (regionURLStr != null)
try{
url[i] = new URL(getDocumentBase(),regionURLStr);
} catch (MalformedURLException e){}
else
url[i] = getDocumentBase();
if (regionHilightBasename != null){
regionHilightImage[i] = getImage(getDocumentBase(),StringConversion.baseString(regionHilightBasename) +
Integer.toString(i) + StringConversion.extString(regionHilightBasename));
tracker.addImage(regionHilightImage[i],HILIGHT_ID + i);
}
if (regionPressedBasename != null){
regionPressedImage[i] = getImage(getDocumentBase(),StringConversion.baseString(regionPressedBasename) +
Integer.toString(i) + StringConversion.extString(regionPressedBasename));
tracker.addImage(regionPressedImage[i],PRESSED_ID + i);
}
}
// Load Audio Parameters
//
// The audio file will be loaded initially and played once
// all of the images in the animation have been loaded.
//
// <PARAM NAME="AUDIO_FILE" VALUE="myaudio.au">
//
String audioFile = getParameter("AUDIO_FILE");
String playOnceStr = getParameter("PLAY_ONCE");
if (audioFile != null)
audio = getAudioClip(getDocumentBase(),audioFile);
// Load all images:
try{
tracker.waitForAll();
} catch (InterruptedException e) {
return;
}
tracker = null;
audio.play();
}
public boolean mouseDown(Event evt, int x, int y){
if ((hilightRegion = locateRegion(x,y)) != -1){
buttonState = PRESSED;
repaint();
}
return true;
}
public boolean mouseUp(Event evt, int x, int y){
buttonState = IDLE;
int mouseDownRegion = hilightRegion;
if ((hilightRegion = locateRegion(x,y)) != -1 &&
hilightRegion == mouseDownRegion)
getAppletContext().showDocument(url[hilightRegion],targetStr);
hilightRegion = -1;
repaint();
return true;
}
private int locateRegion(int x, int y){
for(int i=0;i<regionCount;i++){
if (region[i].inside(x,y)){
return i;
}
}
return -1;
}
public boolean mouseMove(Event evt, int x, int y){
if ((hilightRegion = locateRegion(x,y)) != -1){
buttonState = HILIGHT;
if (helpApplet != null)
helpApplet.showHelp(hilightRegion);
repaint();
}
return true;
}
public boolean mouseExit(Event evt, int x, int y){
buttonState = IDLE;
hilightRegion = -1;
if (helpApplet != null)
helpApplet.showHelp(hilightRegion);
repaint();
return true;
}
public void start(){
// Had to perform this hack becase getApplet("HelpApplet") would not work
// w/ Netscape 2.02S...
for (Enumeration e = getAppletContext().getApplets() ;
e.hasMoreElements() ;){
Object o = e.nextElement();
if (o.getClass().getName().compareTo("HelpApplet") == 0)
helpApplet = (HelpApplet) o;
}
}
}